package com.wingsfrog.puzzle.service.impl;

import com.wingsfrog.puzzle.modules.dao.PictureDao;
import com.wingsfrog.puzzle.modules.dao.UserDao;
import com.wingsfrog.puzzle.modules.entity.Picture;
import com.wingsfrog.puzzle.modules.entity.User;
import com.wingsfrog.puzzle.service.PictureService;
import com.wingsfrog.puzzle.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;

@Service
public class PictureServiceImpl implements PictureService{
    @Autowired
    PictureDao dao;

    @Override
    public void save(Picture picture) {
        dao.save(picture);
    }

    @Override
    public Picture get(Integer picId) {
        Picture picture = dao.findOne(picId);
        if (picture == null) return null;
        picture.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
        dao.save(picture);
        return picture;
    }

    @Override
    public Integer getUserId(Integer picId) {
        // TODO 写一个dao方法直接拿userId
        return dao.findOne(picId).getUserId();
    }
}
